package Love;

public class LoveHeartForXiaoCi {
    public static void main(String[] args) throws InterruptedException {
        int count = 0;
        while (true) {
            System.out.print("\033[H\033[2J"); // 清屏
            System.out.flush();

            // 根据计数器的值改变爱心的大小，实现跳动效果
            double size = 10 + 2 * Math.sin(count * 0.1);

            // 打印爱心
            printHeart(size, count);

            // 打印祝福语
            printBlessing(count);

            count++;
            Thread.sleep(200); // 控制动画速度
            int a = 4;
            byte b = (byte)a;
        }
    }

    // 打印爱心
    private static void printHeart(double size, int count) {
        double x, y;
        for (y = size; y >= -size; y -= 1.5) {
            for (x = -size; x <= size; x += 0.7) {
                double a = x * x + Math.pow(y - Math.pow(Math.abs(x), 0.6), 2);
                if (a <= size * size) {
                    // 使用不同字符创造渐变效果
                    int index = (int) ((count + x + y) % 6);
                    char[] chars = {'❤', '♥', '♡', '❤', '♥', '♡'};
                    System.out.print(chars[index]);
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }

    // 打印祝福语
    private static void printBlessing(int count) {
        String[] messages = {
                "小辞，你最棒！",
                "你是最优秀的！",
                "继续加油哦~",
                "我们为你骄傲！",
                "未来可期！"
        };

        // 闪烁效果
        if (count % 10 < 7) {
            int index = (count / 20) % messages.length;
            System.out.println("\n\033[31m" + centerText(messages[index], 30) + "\033[0m");
        }
    }

    // 居中显示文本
    private static String centerText(String text, int width) {
        if (text.length() >= width) {
            return text;
        }
        int padding = (width - text.length()) / 2;
        return String.format("%" + padding + "s%s%" + padding + "s", "", text, "");
    }
}